package com.example.demo.controller;

import com.example.demo.entity.RegionStats;
import com.example.demo.service.COVID19MsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;

/**
 * Author: wuhaoduan
 * Date: 2021/5/3 14:52
 */

@Controller
public class RegionStatsController {

    @Autowired
    private COVID19MsgService covid19MsgService;

    @GetMapping("/")
    public String getAllMsg(Model model) {
        List<RegionStats> regionStatsList = covid19MsgService.getAllMsg();
        model.addAttribute("list", regionStatsList);
        model.addAttribute("country", "");
        model.addAttribute("state", "");
        return "index";
    }

    @GetMapping("/search")
    public String getMSgByCountry(Model model, @ModelAttribute("country")String country,
                                  @ModelAttribute("state")String state){
        List<RegionStats> regionStatsList = covid19MsgService.getMsgByCountry(country,state);
        model.addAttribute("list", regionStatsList);
        return "index";
    }
}
